using Microsoft.AspNetCore.Mvc;
using star_questionnair.Models;
using star_questionnair.Services;
using star_questionnair.Services.impl;

namespace star_questionnair.Controllers;

[Route("levelQuestionAnalysis")]
[ApiController]
public class LevelQuestionAnalysisController : ControllerBase
{
    private readonly ILevelQuestionAnalysisService _levelQuestionAnalysisService;

    // 构造函数注入服务
    public LevelQuestionAnalysisController(ILevelQuestionAnalysisService levelQuestionAnalysisService)
    {
        _levelQuestionAnalysisService = levelQuestionAnalysisService;
    }

    // 获取某个问题的平均分数
    [HttpGet("levelAverageScore/{questionId}")]
    public async Task<ActionResult<double>> GetLevelAverageScore(int questionId)
    {
        var averageScore = await _levelQuestionAnalysisService.GetAverageScoreAsync(questionId);
        if (averageScore.HasValue)
        {
            return Ok(new{success=true,data=averageScore.Value});
        }

        return Ok(new { message = "No words found." });
    }

    // 获取某个问题的等级排名比例
    [HttpGet("levelRankings/{questionId}")]
    public async Task<ActionResult<Dictionary<int, double>>> GetLevelRankingProportions(int questionId)
    {
        var levelProportions = await _levelQuestionAnalysisService.GetLevelRankingProportionsAsync(questionId);
        if (levelProportions != null && levelProportions.Count > 0)
        {
            return Ok(new{success=true,data=levelProportions});
        }

        return Ok(new { message = "No words found." });
    }
}